import logging
import os
import platform

def is_linux():
    return platform.system() == 'Linux'

def is_windows():
    return platform.system() == 'Windows'

def is_mac():
    return platform.system() == 'Darwin'

def get_flex_swfdump_path(flex_home):
    swfdump_name = 'swfdump.exe' if is_windows() else 'swfdump'
    swfdump_path = os.path.join(flex_home, 'bin', swfdump_name)
    return swfdump_path

def verify_swfdump(swfdump_path):
    if not verify_is_executable(swfdump_path):
        raise IOError('unable to find swfdump: %s' % swfdump_path)
    return swfdump_path

def verify_is_executable(path):
    if not os.path.isfile(path):
        logging.error('file does not exist: %s', path)
        return False
    if not os.access(path, os.X_OK):
        logging.error('file is not executable: %s', path)
        return False
    return True
